package network;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


import java.io.*;
import java.net.Socket;

/**
 *
 * @author ggr
 */
public class Flux {

    public static void transfert(InputStream in, OutputStream out, boolean closeOnExit) throws IOException {
        byte buf[] = new byte[1024];

        int n;
        
        while ((n = in.read(buf)) != -1) {
            System.out.println("Hey");
            out.write(buf, 0, n);
        }

        if (closeOnExit) {
            in.close();
            out.close();
        }
    }

    public static void Recevoir(Socket sock) throws IOException {

        transfert(
                sock.getInputStream(),
                new FileOutputStream("D:\\Run_away.mp3"),
                true);

        sock.close();
    }

    public static void Envoyer(Socket sock) throws IOException {

        transfert(
                new FileInputStream("D:\\native-64bit-flash-installer.sh"),
                sock.getOutputStream(),
                true);

        sock.close();
    }
}
